package com.jwdf.uda.ui.adapter.viewholder;

import android.databinding.DataBindingUtil;
import android.view.View;
import android.widget.ImageView;

import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.databinding.ItemQuizPlanBinding;
import com.jwdf.uda.ui.activity.PhotoActivity;
import com.jwdf.uda.ui.adapter.AbsViewHolder;
import com.jwdf.uda.ui.adapter.item.QuizDetailItem;
import com.jwdf.uda.utils.StringUtils;
import com.jwdf.uda.view.GridImageLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/9/6.
 */
public class QuizPlanViewHolder extends AbsViewHolder<QuizDetailItem> {
    private ItemQuizPlanBinding mItemBinding;

    public QuizPlanViewHolder(View convertView) {
        super(convertView);
        mItemBinding = DataBindingUtil.bind(convertView);
    }

    @Override
    protected void onBindView(QuizDetailItem item) {
        PbBean.PbSignBaseVoteOptionType optionType = item.voteOption.getVoteOption();
        switch (optionType) {
            case VOTE_OPTION_TYPE_A:
                mItemBinding.tvPlanName.setText(R.string.vote_plan_title_a);
                break;
            case VOTE_OPTION_TYPE_B:
                mItemBinding.tvPlanName.setText(R.string.vote_plan_title_b);
                break;
            case VOTE_OPTION_TYPE_C:
                mItemBinding.tvPlanName.setText(R.string.vote_plan_title_c);
                break;
            case VOTE_OPTION_TYPE_D:
                mItemBinding.tvPlanName.setText(R.string.vote_plan_title_d);
                break;
            case VOTE_OPTION_TYPE_E:
                mItemBinding.tvPlanName.setText(R.string.vote_plan_title_e);
                break;
        }
        mItemBinding.divider.setVisibility(item.voteIndex == item.voteOptionCount - 1 ? View.GONE : View.VISIBLE);
        mItemBinding.tvPlanDesc.setText(StringUtils.filterNullAndTrim(item.voteOption.getDescription()));
        final List<PbBean.PbImage> images = item.voteOption.getOptionImageList();
        if (!images.isEmpty()) {
            final ArrayList<String> urls = new ArrayList<>();
            for (PbBean.PbImage image : images) {
                urls.add(image.getUrl());
            }
            mItemBinding.gridimageLayout.setImage(urls);
            mItemBinding.gridimageLayout.setOnImageItemClickListener(new GridImageLayout.OnImageItemClickListener() {
                @Override
                public void onImageClick(int index, ImageView imageView) {
                    PhotoActivity.start(imageView.getContext(), urls, index);
                }
            });
        } else {
            mItemBinding.gridimageLayout.setVisibility(View.GONE);
        }

    }
}
